package com.smart.common.config.datasource;


import com.alicp.jetcache.Cache;
import com.smart.common.cache.CacheService;
import com.smart.common.entities.option.SelectOptionMap;
import com.smart.manager.system.repository.DictRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * ebean初始化Ebean需要的处理器
 *
 * @author 夏绪秋
 * @date 2023-01-17
 */

@Component
@Log4j2
@RequiredArgsConstructor
public class EbeanRegPlugs {

    private final EbeanConfiguration ebeanConfiguration;
    private final DictRepository dictRepository;

    private final CacheService cacheService;

    @PostConstruct
    public void regDictTranslatorHandler() {

        log.warn("初始化数据库字典翻译");

        Cache<String, List<SelectOptionMap>> dictCache = cacheService.getDictCache();
        // 设置翻译器
        ebeanConfiguration.setTranslatorHandler(dictCache, dictRepository);
    }


}
